package com.badibadi.slide;

import android.app.Activity;
//import android.content.Intent;
//import android.os.Bundle;
import android.os.Parcelable;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import java.util.List;

public class ViewPagerAdapters extends PagerAdapter {
    private List<View> views;
    //private Activity activity;
    LayoutInflater factory;

    public ViewPagerAdapters(List<View> views, Activity activity) {
        this.views = views;
        //this.activity = activity;
    }

    @Override
    public void destroyItem(View arg0, int arg1, Object arg2) {
        // ((ViewPager) arg0).removeView(list.get(arg1%list.size()));
    }

    @Override
    public int getCount() {
        if (views.size() == 1) {
            return views.size();
        }
        return Integer.MAX_VALUE;
    }

    @Override
    public boolean isViewFromObject(View arg0, Object arg1) {
        return (arg0 == arg1);
    }

    @Override
    public Object instantiateItem(ViewGroup container, final int position) {
        if (views.size() == 0) {
            return null;
        }
        if (views.size() == 1) {
            ((ViewPager) container).addView(views.get(position), 0);
            // return views.get(position);
        }
        if (views.get(position % views.size()).getParent() == null) {
            ((ViewPager) container).addView(views.get(position % views.size()), 0);
        } else {
            ((ViewGroup) views.get(position % views.size()).getParent()).removeView(views
                    .get(position % views.size()));
            ((ViewPager) container).addView(views.get(position % views.size()), 0);
        }
       /* views.get(position % views.size()).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Bundle bundle = new Bundle();
                if (list3.size() > 3) {
                    bundle.putString("id", list3.get(position % views.size()).id.toString());
                    bundle.putString("count", list3.get(position % views.size()).commentcount.toString());
                } else if (list3.size() > 0 && list3.size() <= 3) {
                    bundle.putString("id", list3.get(position % list3.size()).id.toString());
                    bundle.putString("count", list3.get(position % list3.size()).commentcount.toString());
                }
                Intent intent = new Intent();
                intent.putExtras(bundle);
                intent.setClass(activity, DetailedNewsContentActivity.class);
                if (list3.size() > 0) {
                    activity.startActivity(intent);
                }
            }
        });*/
        return views.get(position % views.size());
    }

    @Override
    public Parcelable saveState() {
        return null;
    }

}

